/* $Id$ */
package org.crazydays.gameplan.map.swing;


import java.lang.reflect.Method;

import javax.swing.JComboBox;
import javax.swing.JSpinner;
import javax.swing.JTextField;

import org.junit.*;

import static org.easymock.EasyMock.*;
import static org.easymock.classextension.EasyMock.*;

import org.crazydays.gameplan.Controller;
import org.crazydays.gameplan.map.GameMap;
import org.crazydays.gameplan.map.GridType;
import org.crazydays.gameplan.map.IGameMap;

/**
 * JCreateMapDialogUnitTest
 */
public class JCreateMapDialogUnitTest
{
    /**
     * Test createMap().
     * 
     * @throws NoSuchMethodException
     * @throws SecurityException
     */
    @Test
    public void testCreateMap()
        throws SecurityException, NoSuchMethodException
    {
        // object
        IGameMap gameMap = new GameMap("name", 480, 640, GridType.SQUARE, 20);

        // mocks
        JCreateMapDialog dialog =
            createMock(JCreateMapDialog.class,
                new Method[] { JCreateMapDialog.class.getMethod("setVisible",
                    Boolean.TYPE) });
        JTextField nameInput = createMock(JTextField.class);
        JComboBox typeInput = createMock(JComboBox.class);
        JSpinner heightInput = createMock(JSpinner.class);
        JSpinner widthInput = createMock(JSpinner.class);
        Controller controller = createMock(Controller.class);

        // expect
        expect(nameInput.getText()).andReturn("name");
        expect(typeInput.getSelectedIndex()).andReturn(0);
        expect(heightInput.getValue()).andReturn(480);
        expect(widthInput.getValue()).andReturn(640);
        controller.addGameMap(gameMap);
        dialog.setVisible(false);

        // replay
        replay(dialog, nameInput, typeInput, heightInput, widthInput,
            controller);

        // setup
        dialog.nameInput = nameInput;
        dialog.typeInput = typeInput;
        dialog.heightInput = heightInput;
        dialog.widthInput = widthInput;
        dialog.controller = controller;

        // test
        dialog.actionPerformed(null);

        // verify
        verify(dialog, nameInput, typeInput, heightInput, widthInput,
            controller);
    }
}
